| Conditions | 1 |
| Paths | 1 |
| Total Lines | 126 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /* |
||
| 14 | ], function($, Manager, Router) { |
||
| 15 | |||
| 16 | 'use strict'; |
||
| 17 | |||
| 18 | return { |
||
| 19 | |||
| 20 | defaults: { |
||
| 21 | translations: { |
||
| 22 | headline: 'sulu_comment.threads' |
||
| 23 | } |
||
| 24 | }, |
||
| 25 | |||
| 26 | header: function() { |
||
| 27 | var buttons = { |
||
| 28 | save: {}, |
||
| 29 | edit: { |
||
| 30 | options: { |
||
| 31 | dropdownItems: { |
||
| 32 | delete: { |
||
| 33 | options: { |
||
| 34 | callback: this.delete.bind(this) |
||
| 35 | } |
||
| 36 | } |
||
| 37 | } |
||
| 38 | } |
||
| 39 | } |
||
| 40 | }; |
||
| 41 | |||
| 42 | return { |
||
| 43 | title: function() { |
||
| 44 | return this.translations.headline; |
||
| 45 | }.bind(this), |
||
| 46 | |||
| 47 | tabs: { |
||
| 48 | url: '/admin/content-navigations?alias=threads', |
||
| 49 | options: { |
||
| 50 | data: function() { |
||
| 51 | return this.sandbox.util.extend(false, {}, this.data); |
||
| 52 | }.bind(this) |
||
| 53 | }, |
||
| 54 | componentOptions: { |
||
| 55 | values: this.data |
||
| 56 | } |
||
| 57 | }, |
||
| 58 | |||
| 59 | toolbar: { |
||
| 60 | buttons: buttons |
||
| 61 | } |
||
| 62 | }; |
||
| 63 | }, |
||
| 64 | |||
| 65 | loadComponentData: function() { |
||
| 66 | var promise = $.Deferred(); |
||
| 67 | |||
| 68 | if (!this.options.id) { |
||
| 69 | promise.resolve({}); |
||
| 70 | |||
| 71 | return promise; |
||
| 72 | } |
||
| 73 | Manager.load(this.options.id).done(function(data) { |
||
| 74 | promise.resolve(data); |
||
| 75 | }); |
||
| 76 | |||
| 77 | return promise; |
||
| 78 | }, |
||
| 79 | |||
| 80 | initialize: function() { |
||
| 81 | this.bindCustomEvents(); |
||
| 82 | }, |
||
| 83 | |||
| 84 | bindCustomEvents: function() { |
||
| 85 | this.sandbox.on('sulu.header.back', Router.toList); |
||
| 86 | this.sandbox.on('sulu.tab.dirty', this.enableSave.bind(this)); |
||
| 87 | this.sandbox.on('sulu.toolbar.save', this.save.bind(this)); |
||
| 88 | this.sandbox.on('sulu.tab.data-changed', this.setData.bind(this)); |
||
| 89 | }, |
||
| 90 | |||
| 91 | delete: function() { |
||
| 92 | this.sandbox.emit('sulu.header.toolbar.item.loading', 'edit'); |
||
| 93 | |||
| 94 | Manager.delete(this.data.id).done(function() { |
||
| 95 | this.sandbox.emit('sulu.header.toolbar.item.enable', 'edit', false); |
||
| 96 | Router.toList(); |
||
| 97 | }.bind(this)); |
||
| 98 | }, |
||
| 99 | |||
| 100 | save: function(action) { |
||
| 101 | this.loadingSave(); |
||
| 102 | |||
| 103 | this.saveTab().then(function(data) { |
||
| 104 | this.afterSave(action, data); |
||
| 105 | }.bind(this)); |
||
| 106 | }, |
||
| 107 | |||
| 108 | setData: function(data) { |
||
| 109 | this.data = data; |
||
| 110 | }, |
||
| 111 | |||
| 112 | saveTab: function() { |
||
| 113 | var promise = $.Deferred(); |
||
| 114 | |||
| 115 | this.sandbox.once('sulu.tab.saved', function(savedData) { |
||
| 116 | this.setData(savedData); |
||
| 117 | |||
| 118 | promise.resolve(savedData); |
||
| 119 | }.bind(this)); |
||
| 120 | |||
| 121 | this.sandbox.emit('sulu.tab.save'); |
||
| 122 | |||
| 123 | return promise; |
||
| 124 | }, |
||
| 125 | |||
| 126 | enableSave: function() { |
||
| 127 | this.sandbox.emit('sulu.header.toolbar.item.enable', 'save', false); |
||
| 128 | }, |
||
| 129 | |||
| 130 | loadingSave: function() { |
||
| 131 | this.sandbox.emit('sulu.header.toolbar.item.loading', 'save'); |
||
| 132 | }, |
||
| 133 | |||
| 134 | afterSave: function(action, data) { |
||
| 135 | this.sandbox.emit('sulu.header.toolbar.item.disable', 'save', true); |
||
| 136 | this.sandbox.emit('sulu.header.saved', data); |
||
| 137 | } |
||
| 138 | }; |
||
| 139 | }); |
||
| 140 |